package ru.ssau.university.persistence.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import ru.ssau.hibernate.util.AbstractDAO;
import ru.ssau.university.persistence.entity.Schedule;

public class ScheduleDAO extends AbstractDAO<Schedule>{
	public ScheduleDAO() {
		this.objectClass = Schedule.class;
	}
	
	@SuppressWarnings("unchecked")
	public Schedule getSchedule(Long groupId, int week, int dayOfWeek, int lesson) {
		Criteria c = createCriteria();
		c.add(Restrictions.eq("week", week));
		c.add(Restrictions.eq("dayOfWeek", dayOfWeek));
		c.add(Restrictions.eq("lesson", lesson));
		c.add(Restrictions.eq("group.id", groupId));
		List<Schedule> list = (List<Schedule>) c.list();
		if (list.size() == 0) {
			return null;
		} else {
			return (Schedule) list.get(0);
		}
	}
}
